package mya.mes.mdc.model.tag.convert;

import mya.mes.mdc.model.excel.ExcelData;
import mya.mes.mdc.model.tag.MdcTag;

import java.util.ArrayList;
import java.util.List;

public class TagHolderUpdate {

    public List<MdcTag> process(ExcelData excelData) {
        MdcTagBuilder mdcTagBuilder = new MdcTagBuilder();
        List<MdcTag> mdcTagList = mdcTagBuilder.build(excelData.shop, excelData.area, excelData.tagDefList);

        AlarmTagBuilder alarmTagBuilder = new AlarmTagBuilder();
        List<MdcTag> mdcTagAlarmList = alarmTagBuilder.build(excelData.shop, excelData.area, excelData.tagAlarmDefList);

        int mdcTagListSize = 0;
        int mdcAlarmTagListSize = 0;

        List<MdcTag> allList;
        if (mdcTagList != null && mdcTagAlarmList != null) {
            allList = new ArrayList<>(mdcTagList.size() + mdcTagAlarmList.size());
            allList.addAll(mdcTagList);
            allList.addAll(mdcTagAlarmList);
            mdcTagListSize = mdcTagList.size();
            mdcAlarmTagListSize = mdcTagAlarmList.size();
        } else if (mdcTagList != null) {
            allList = mdcTagList;
            mdcTagListSize = mdcTagList.size();
        } else if (mdcTagAlarmList != null) {
            allList = mdcTagAlarmList;
            mdcAlarmTagListSize = mdcTagAlarmList.size();
        } else {
            allList = null;
        }
        System.out.println("mdcTagList.size = " + mdcTagListSize + ", mdcAlarmTagListSize = " + mdcAlarmTagListSize);
        if (allList != null) {
            allList.forEach(tag -> {
                tag.buildKey();
            });
        }
        return allList;
    }
}
